﻿using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;
using Rafy.Book.Views;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;

namespace Rafy.Book.ViewModels
{
    public class FmPrintViewModel : BindableBase, IDialogAware
    {
        private ObservableCollection<BookWordModel> _lstWords;
        public ObservableCollection<BookWordModel> lstWords
        {
            get => _lstWords;
            set => SetProperty(ref _lstWords, value);
        }
        private bool _onlyPrintPinyin;
        public bool OnlyPrintPinyin
        {
            get => _onlyPrintPinyin;
            set
            {
                SetProperty(ref _onlyPrintPinyin, value);
            }
        }

        private bool _onlyPrintCharacter;
        public bool OnlyPrintCharacter
        {
            get => _onlyPrintCharacter;
            set
            {
                SetProperty(ref _onlyPrintCharacter, value);
            }
        }

        public DelegateCommand PrintCommand { get; private set; }
        public FmPrintViewModel()
        {
            //lstWords = new ObservableCollection<BookWordModel>();
            PrintCommand = new DelegateCommand(OnPrint);
        }

        private void OnPrint()
        {
            throw new NotImplementedException();
        }

        public string Title => "打印字词";


        public DialogCloseListener RequestClose { get; }

        //这个方法是允许关闭窗口
        public bool CanCloseDialog()
        {
            return true;
        }
        //关闭方法
        public void OnDialogClosed()
        {
            //RequestClose.Invoke(ButtonResult.Cancel);
            //MessageBox.Show("关闭窗口");
        }
        //打开之前传递过来的参数
        public void OnDialogOpened(IDialogParameters parameters)
        {
            //从上页面中传过来的参数
            var lst = parameters.GetValue<List<BookWordModel>>("objs");
            lstWords = new ObservableCollection<BookWordModel>(lst);
            Console.WriteLine($"lstWords={lstWords.Count}");

        }
    }
}
